<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="登记中心行号" prop="bdcno">
      <el-input v-model="dataForm.bdcno" placeholder="登记中心行号"></el-input>
    </el-form-item>
    <el-form-item label="银行参与者行号" prop="bankid">
      <el-input v-model="dataForm.bankid" placeholder="银行参与者行号"></el-input>
    </el-form-item>
    <el-form-item label="用户名" prop="login">
      <el-input v-model="dataForm.login" placeholder="用户名"></el-input>
    </el-form-item>
    <el-form-item label="登录时间" prop="logintime">
      <el-input v-model="dataForm.logintime" placeholder="登录时间"></el-input>
    </el-form-item>
    <el-form-item label="登录结果" prop="status">
      <el-input v-model="dataForm.status" placeholder="登录结果"></el-input>
    </el-form-item>
    <el-form-item label="结果描述" prop="descinfo">
      <el-input v-model="dataForm.descinfo" placeholder="结果描述"></el-input>
    </el-form-item>
    <el-form-item label="超期时间" prop="expire">
      <el-input v-model="dataForm.expire" placeholder="超期时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          seqno: 0,
          bdcno: '',
          bankid: '',
          login: '',
          logintime: '',
          status: '',
          descinfo: '',
          expire: ''
        },
        dataRule: {
          bdcno: [
            { required: true, message: '登记中心行号不能为空', trigger: 'blur' }
          ],
          bankid: [
            { required: true, message: '银行参与者行号不能为空', trigger: 'blur' }
          ],
          login: [
            { required: true, message: '用户名不能为空', trigger: 'blur' }
          ],
          logintime: [
            { required: true, message: '登录时间不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '登录结果不能为空', trigger: 'blur' }
          ],
          descinfo: [
            { required: true, message: '结果描述不能为空', trigger: 'blur' }
          ],
          expire: [
            { required: true, message: '超期时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.seqno = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.seqno) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdclogin/info/${this.dataForm.seqno}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.bdcno = data.bdcLogin.bdcno
                this.dataForm.bankid = data.bdcLogin.bankid
                this.dataForm.login = data.bdcLogin.login
                this.dataForm.logintime = data.bdcLogin.logintime
                this.dataForm.status = data.bdcLogin.status
                this.dataForm.descinfo = data.bdcLogin.descinfo
                this.dataForm.expire = data.bdcLogin.expire
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdclogin/${!this.dataForm.seqno ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'seqno': this.dataForm.seqno || undefined,
                'bdcno': this.dataForm.bdcno,
                'bankid': this.dataForm.bankid,
                'login': this.dataForm.login,
                'logintime': this.dataForm.logintime,
                'status': this.dataForm.status,
                'descinfo': this.dataForm.descinfo,
                'expire': this.dataForm.expire
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
